package com.y.fund.aacore.enums;

public enum BoolVal {
	Yes(1,"YES"), No(0,"NO");
       
    private final int val;
    private final String name;

    BoolVal(int value, String name) {
        this.val = value;
        this.name = name;
    }

    public int getVal() {
        return val;
    }

    public String getName() {
        return name;
    }

    public static boolean IsYes(Object value) {
    	if(null==value) {
    		return false;
    	}
    	if(value instanceof Integer val) {
            if (BoolVal.No.getVal() == val) {
                return false;
            }
            return (val != 0);
    	}else{
        	String s = value.toString().toLowerCase().trim();
        	return (s.equals("1") || s.equals("y") || s.equals("yes") || s.equals("t") || s.equals("true"));
    	}
    }
    
    public static BoolVal ofVal(Integer val) {
        if (null != val) {
            for (BoolVal boolVal : BoolVal.values()) {
                if (val.equals(boolVal.getVal())){
                    return boolVal;
                }
            }
        }
        return null;
    }
}
